/**
 * @project_name staff_vehicle
 * @package_name com.ssh.web.admin
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-26
 * @time 下午4:23:47
 */
package com.ssh.web.admin;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.Staff;
import com.ssh.ser.admin.StaffManageSerI;
import com.ssh.util.UploadFileUtil;

/**
 * @author jack
 *
 */
public class AddNewStaffAction extends ActionSupport {
	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;
	private String address;
	private String birthday;
	private String education;
	private String email;
	private String firstName;
	private String idNumber;
	private String lastName;
	private String marriage;
	private String picture;
	private String politicsState;
	private short staffPermission;
	private String sex;
	private String workerId;
	StaffManageSerI staffManageSerI;
	private Long staffTel;
	

	public String getWorkerId() {
		return workerId;
	}

	public void setWorkerId(String workerId) {
		this.workerId = workerId;
	}

	private File pic;
	private String picFileName;
	private String picContentType;

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			// ActionContext.getContext().getSession();
			if(!workerId.equals("")&&!staffTel.equals("")){
				Staff staff = new Staff();
				staff.setAddress(address);
				SimpleDateFormat sdf  =   new  SimpleDateFormat("yyyy-MM-dd");
				staff.setBirthday(sdf.parse(birthday));
				staff.setEducation(education);
				staff.setEmail(email);
				staff.setFirstName(firstName);
				staff.setIdNumber(idNumber);
				staff.setLastName(lastName);
				staff.setMarriage(marriage);
				staff.setPicture(picture);
				staff.setPoliticsState(politicsState);
				staff.setStaffPermission(staffPermission);
				staff.setSex(sex);
				staff.setStaffTel(staffTel);
				staff.setPassword("123456");
				staff.setStaffId(workerId);
				System.out.println("staff:" + staff);
				
				if(null != pic){
					String path = "upload/image_staff_vehicle";
					boolean sta = UploadFileUtil.save(pic, picFileName, path);
					if(sta){
						staff.setPicture(path+"/"+picFileName);
					}
				}
				
				staffManageSerI.addStaff(staff);
			}
			
			return "ok";
		}catch(ParseException p){
			p.printStackTrace();
			return "error";
		}
		catch (Exception e) {
			e.printStackTrace();
			return "error";
		}

	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}


	public int getStaffPermission() {
		return staffPermission;
	}

	public void setStaffPermission(short staffPermission) {
		this.staffPermission = staffPermission;
	}

	/**
	 * @return the education
	 */
	public String getEducation() {
		return education;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @return the idNumber
	 */
	public String getIdNumber() {
		return idNumber;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @return the marriage
	 */
	public String getMarriage() {
		return marriage;
	}

	/**
	 * @return the picture
	 */
	public String getPicture() {
		return picture;
	}

	/**
	 * @return the politicsState
	 */
	public String getPoliticsState() {
		return politicsState;
	}

	/**
	 * @return the sex
	 */
	public String getSex() {
		return sex;
	}

	/**
	 * @return the staffManageSerI
	 */
	public StaffManageSerI getStaffManageSerI() {
		return staffManageSerI;
	}

	/**
	 * @return the staffTel
	 */
	public Long getStaffTel() {
		return staffTel;
	}

	/**
	 * @param address
	 *            the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @param education
	 *            the education to set
	 */
	public void setEducation(String education) {
		this.education = education;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param firstName
	 *            the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @param idNumber
	 *            the idNumber to set
	 */
	public void setIdNumber(String idNumber) {
		this.idNumber = idNumber;
	}

	/**
	 * @param lastName
	 *            the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @param marriage
	 *            the marriage to set
	 */
	public void setMarriage(String marriage) {
		this.marriage = marriage;
	}

	/**
	 * @param picture
	 *            the picture to set
	 */
	public void setPicture(String picture) {
		this.picture = picture;
	}

	/**
	 * @param politicsState
	 *            the politicsState to set
	 */
	public void setPoliticsState(String politicsState) {
		this.politicsState = politicsState;
	}

	/**
	 * @param sex
	 *            the sex to set
	 */
	public void setSex(String sex) {
		this.sex = sex;
	}


	/**
	 * @param staffManageSerI
	 *            the staffManageSerI to set
	 */
	public void setStaffManageSerI(StaffManageSerI staffManageSerI) {
		this.staffManageSerI = staffManageSerI;
	}

	/**
	 * @param staffTel
	 *            the staffTel to set
	 */
	public void setStaffTel(Long staffTel) {
		this.staffTel = staffTel;
	}

	/**
	 * @return the birthday
	 */
	public String getBirthday() {
		return birthday;
	}

	/**
	 * @param birthday the birthday to set
	 */
	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public File getPic() {
		return pic;
	}

	public void setPic(File pic) {
		this.pic = pic;
	}

	public String getPicFileName() {
		return picFileName;
	}

	public void setPicFileName(String picFileName) {
		this.picFileName = picFileName;
	}

	public String getPicContentType() {
		return picContentType;
	}

	public void setPicContentType(String picContentType) {
		this.picContentType = picContentType;
	}

	
}
